package com.codefish.codefish_blog.controller;

import com.codefish.codefish_blog.ajax.AjaxResult;
import com.codefish.codefish_blog.exception.AccountException;
import com.sun.javafx.collections.MappingChange;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.UserException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author codefish
 * @version 1.0
 * @date 2022/04/04 下午 09:36
 */
@ControllerAdvice
@Slf4j
public class ExceptionController {
    @ExceptionHandler(AccountException.class)
    @ResponseBody
    public AjaxResult userException(AccountException e, HttpServletRequest request) {
        log.error("[来自{}的请求] 用户登录/注册异常：{}", request.getRemoteAddr(), e.getMessage());
        return AjaxResult.fail(e.getMessage());
    }
}
